package service.rocksea.com.serviceapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.net.DatagramSocket;

public class MainActivity extends AppCompatActivity {

    private CommThread commThread;
    private DatagramSocket socket;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button json = (Button) findViewById(R.id.button4);
        final Button close = (Button) findViewById(R.id.button3);
        Button open = (Button) findViewById(R.id.button2);
        Button send = (Button) findViewById(R.id.button);
        TextView info = (TextView) findViewById(R.id.textView);

        json.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });


        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                commThread.turnDown();

            }
        });


        open.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                if (socket==null)
                    socket = CommThread.createWifiSocket();
                try {
                    commThread = new CommThread(socket,MainActivity.this);
                    commThread.start();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                commThread.sendJson(Const.JSON);
            }
        });







    }
}
